from wtforms import StringField, SelectMultipleField, IntegerField, SelectField
from wtforms.validators import NumberRange, Optional

from apps.a_common.constants import SKILL_CHOICE, PROJECT_STATUS_CHOICE, PROCESS_STATUS_CHOICE, \
    CHECK_LIST_STATUS_CHOICE, CHECK_LIST_TYPE_CHOICE
from apps.a_common.request import MyFlaskForm, ArrayField


class ProjectSearchForm(MyFlaskForm):
    user_id = IntegerField('用户的id')
    status = SelectField('项目状态', [Optional()], coerce=int, choices=PROJECT_STATUS_CHOICE)


class ProjectEditorForm(MyFlaskForm):
    user_ids = ArrayField('参与项目的个人', coerce=int)
    name = StringField('项目的名称')
    backend = StringField('项目背景')
    start_at = IntegerField('项目启动时间', [NumberRange(0), Optional()])
    end_at = IntegerField('项目结束时间', [NumberRange(0), Optional()])
    need_skills = SelectMultipleField('', choices=SKILL_CHOICE, coerce=int)
    status = SelectField('项目状态', [Optional()], coerce=int, choices=PROJECT_STATUS_CHOICE)


class ProcessSearchForm(MyFlaskForm):
    project_id = IntegerField('项目的id')
    status = SelectField('流程状态', [Optional()], coerce=int, choices=PROCESS_STATUS_CHOICE)


class ProcessEditorForm(MyFlaskForm):
    name = StringField('环节的名称')
    start_at = IntegerField('环节启动时间', [NumberRange(0), Optional()])
    end_at = IntegerField('环节结束时间', [NumberRange(0), Optional()])
    status = SelectField('环节的状态', [Optional()], coerce=int, choices=PROJECT_STATUS_CHOICE)
    project_id = IntegerField('项目的id')


class CheckListSearchForm(MyFlaskForm):
    process_id = IntegerField('环节的id')
    project_id = IntegerField('项目的id')
    status = SelectField('清单条款的状态', [Optional()], coerce=int, choices=CHECK_LIST_STATUS_CHOICE)
    type = SelectField('清单条款的类型', [Optional()], coerce=int, choices=CHECK_LIST_TYPE_CHOICE)


class CheckListEditorForm(MyFlaskForm):
    name = StringField('清单条目的名称')
    start_at = IntegerField('清单条目启动时间', [NumberRange(0), Optional()])
    end_at = IntegerField('清单条目结束时间', [NumberRange(0), Optional()])
    status = SelectField('清单条款的状态', [Optional()], coerce=int, choices=CHECK_LIST_STATUS_CHOICE)
    type = SelectField('清单条款的类型', [Optional()], coerce=int, choices=CHECK_LIST_TYPE_CHOICE)
    user_id = IntegerField('用户的id')
    process_id = IntegerField('环节的id')
